package com.use;

public class Encap {

    public static void main(String[] args) {

        Person p = new Person();

        p.setName("jeck");
        p.setAge(23);
        p.setSalay(28000.00);
        System.out.println(p.info());
//        System.out.println(p.getSalay());

        Person p2 = new Person("小王",23,28000.00);


    }

}


class Person{
    public String name;
    private int age;
    private double salay;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age >= 1 && age <= 120){
            this.age = age;
        }else{
            System.out.println("年龄不能小于1大于120");
        }
    }

    public double getSalay() {
        return salay;
    }

    public  Person(){
        System.out.println("无参构造方法");
//        this.name = name;
//        this.age = age;
//        this.salay = salay;
    }

    public Person(String name, int age, double salay) {
//        this.name = name;
//        this.age = age;
//        this.salay = salay;
        setName(name);
        setAge(age);
        setSalay(salay);
    }

    public void setSalay(double salay) {
        this.salay = salay;
    }

    public  String info(){
        return  "Person{name:"+this.name+",age:"+this.age+",salay:"+this.salay+"}";
    }
}
